home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / coordtext.cls < prev    next >
Encoding:
Visual Basic class definition  |  2004-03-05  |  12.5 KB  |  397 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Coordinate"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14.  
  15. Option Explicit
  16. '/******************************************************************/
  17. '/*                                                                */
  18. '/*                      TurboCAD for Windows                      */
  19. '/*                   Copyright (c) 1993 - 2001                    */
  20. '/*             International Microcomputer Software, Inc.         */
  21. '/*                            (IMSI)                              */
  22. '/*                      All rights reserved.                      */
  23. '/*                                                                */
  24. '/******************************************************************/
  25.  
  26. 'DBAPI constants
  27. Const gkGraphic = 11
  28. Const gkArc = 2
  29. Const gkText = 6
  30. Const gfCosmetic = 128&
  31.  
  32. 'Stock property pages
  33. Const ppStockPen = 1
  34. Const ppStockBrush = 2
  35. Const ppStockText = 4
  36. Const ppStockInsert = 8
  37. Const ppStockViewport = 16
  38. Const ppStockAuto = 32
  39.  
  40. 'Real variant types!
  41. Const typeEmpty = 0
  42. Const typeInteger = 2
  43. Const typeLong = 3
  44. Const typeSingle = 4
  45. Const typeDouble = 5
  46. Const typeCurrency = 6
  47. Const typeDate = 7
  48. Const typeString = 8
  49. Const typeObject = 9
  50. Const typeBoolean = 11
  51. Const typeVariant = 12
  52. Const typeIntegerEnum = typeInteger + 100
  53. Const typeLongEnum = typeLong + 100
  54. Const typeStringEnum = typeString + 100
  55.  
  56. 'Property Ids
  57. Const idCoordStyle = 1
  58. Const idTextHeight = 2
  59. Const idMarkSize = 3
  60.  
  61.  
  62. 'Property enums
  63. Const NUM_TYPES = 3
  64. Const dotted = 0
  65. Const stacked = 1
  66. Const cartesian = 2
  67.  
  68.  
  69. 'Number of properties, pages, wizards
  70. Const NUM_PROPERTIES = 3
  71. Const NUM_PAGES = 1
  72. Const NUM_WIZARDS = 0
  73. Const formCaption = "Coordinate Text"
  74.  
  75. Private Sub Class_Initialize()
  76.     'Initialize class variables
  77. End Sub
  78.  
  79. 'Returns the user-visible description of this RegenMethod
  80. Public Property Get Description() As String
  81.     Description = "SDK Coordinate Text"
  82. End Property
  83.  
  84. 'Returns the persistent class id for this RegenMethod's property section
  85. Public Property Get ClassID() As String
  86.     ClassID = "{1B91F522-8900-11d0-AFFD-444553540000}"
  87. End Property
  88.  
  89. 'Retrieve types and names
  90. Public Function GetPropertyInfo(Names As Variant, Types As Variant, IDs As Variant, Defaults As Variant) As Long
  91.     ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
  92.  
  93.     Names(0) = "CoordType"
  94.     Types(0) = typeLong
  95.     IDs(0) = idCoordStyle
  96.     Defaults(0) = dotted
  97.  
  98.     Names(1) = "TextHeight"
  99.     Types(1) = typeDouble
  100.     IDs(1) = idTextHeight
  101.     Defaults(1) = 0.3
  102.  
  103.     Names(2) = "MarkSize"
  104.     Types(2) = typeDouble
  105.     IDs(2) = idMarkSize
  106.     Defaults(2) = 0.05
  107.  
  108.     GetPropertyInfo = NUM_PROPERTIES
  109. End Function
  110.  
  111. 'Get the number of property pages supporting this RegenMethod
  112. Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, Names As Variant) As Long
  113.     ReDim Names(NUM_PAGES)
  114.  
  115.     'Need the form
  116. ''    Load frmCoordText
  117. ''    Names(0) = frmCoordText.Caption
  118. ''    Unload frmCoordText
  119.     Names(0) = formCaption
  120.     'Set up which property pages we want to see
  121.     StockPages = ppStockPen + ppStockAuto
  122.  
  123.     GetPageInfo = NUM_PAGES
  124. End Function
  125.  
  126. Public Function GetWizardInfo(Names As Variant) As Long
  127.     ReDim Names(NUM_WIZARDS)
  128.     GetWizardInfo = NUM_WIZARDS
  129. End Function
  130.  
  131. 'Enumerate the names and values of a specified property
  132. Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long
  133.     If PropID = idCoordStyle Then
  134.         ReDim Names(NUM_TYPES), Values(NUM_TYPES)
  135.         Names(0) = "Dotted"
  136.         Values(0) = dotted
  137.         Names(1) = "Stacked"
  138.         Values(1) = stacked
  139.         Names(2) = "Cartesian"
  140.         Values(2) = cartesian
  141.         GetEnumNames = NUM_TYPES
  142.     Else
  143.         GetEnumNames = 0
  144.     End If
  145. End Function
  146.  
  147. Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic1 As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
  148.         On Error GoTo Failed
  149. Dim Graphic As Graphic
  150.     Set Graphic = Graphic1
  151.         Dim i%
  152.         If ThisRegenMethod.Name <> Graphic.Type And Graphic.Type <> "GRAPHIC" Then Exit Function
  153.         If SaveProperties Then
  154.            With frmCoordText
  155.                 'When the property page is closed,
  156.                 'Get properties from the property pages
  157.  
  158.                 For i% = 0 To NUM_TYPES
  159.                     If .CoordType(i%).Value Then
  160.                         Graphic.Properties("CoordType") = i%
  161.                         Exit For
  162.                     End If
  163.                 Next i%
  164.  
  165.                 Graphic.Properties("MarkSize") = CDbl(.MarkSize.Text)
  166.                 Graphic.Properties("TextHeight") = CDbl(.TxtHeight.Text)
  167.  
  168.             End With
  169.         Else
  170.             'Property page is about to be opened
  171.             'Make sure the form is loaded
  172.             Load frmCoordText
  173.             With frmCoordText
  174.                 'When the property page is opening,
  175.  
  176.                 Dim CoordProp As Variant
  177.  
  178.                 'If more than one CoordText shape is selected and they
  179.                 'do not have the same properties, don't set up this field
  180.                 On Error GoTo NoCType
  181.                 CoordProp = Graphic.Properties("CoordType")
  182.                 If VarType(CoordProp) <> vbEmpty Then
  183.                        i% = CInt(CoordProp)
  184.                        .CoordType(i%).Value = True
  185.                 End If
  186. NoCType:
  187.                 'If we don't have the same marker size, skip setting up this
  188.                 'field also
  189.                 On Error GoTo NoMType
  190.                 .MarkSize.Text = Graphic.Properties("MarkSize")
  191.  
  192. NoMType:
  193.                 'If we don't have the same text size, skipp setting up
  194.                 'this field
  195.                 On Error GoTo NoTType
  196.                 .TxtHeight.Text = Graphic.Properties("TextHeight")
  197.  
  198. NoTType:
  199.             End With
  200.         End If
  201.  
  202.  
  203.         PageControls = True
  204.         Exit Function
  205.  
  206. Failed:
  207.         PageControls = False
  208. End Function
  209.  
  210. Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
  211.         'Done with form
  212.         Unload frmCoordText
  213. End Function
  214.  
  215. Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
  216.     With frmCoordText
  217.         .Show vbModal
  218.         PropertyPages = Not .DialogCanceled
  219.     End With
  220. End Function
  221.  
  222. Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
  223.     Wizard = False
  224. End Function
  225.  
  226. 'Called when vertex has been moved, or other geometry change
  227. Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
  228.     'Regen Graphic
  229. End Function
  230.  
  231. 'Called when vertex is moved, or other geometry change
  232. Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
  233.     'OK to continue with change
  234.     OnGeometryChanging = True
  235. End Function
  236.  
  237. Public Function OnNewGraphic(ByVal grfThis As Object, ByVal boolCopy As Boolean) As Boolean
  238.     If boolCopy Then
  239.         'Vertices are already added for us...
  240.         OnNewGraphic = True
  241.         Exit Function
  242.     End If
  243.  
  244.     On Error GoTo Failed
  245.     'New Graphic being created
  246.     'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
  247.  
  248.     'First Vertex - "left bottom" - v0
  249.     grfThis.Vertices.Add 0#, 0#, 0#, False, True, True, True, False
  250.  
  251.     'Limit the number of vertices allowed with this Smart Object
  252.     grfThis.Properties("LimitVertices") = True
  253.  
  254.     OnNewGraphic = True
  255.     Exit Function
  256.  
  257. Failed:
  258.     'Return false on failure
  259.     OnNewGraphic = False
  260. End Function
  261.  
  262. 'Function called whenever a copy of a graphic is being made
  263. Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
  264.     'Return false on failure
  265.     OnCopyGraphic = True
  266. End Function
  267.  
  268. 'Notification function called after graphic property is saved
  269. Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
  270.         ValueOld As Variant, ValueNew As Variant)
  271.     'Regen Graphic
  272. End Function
  273.  
  274. 'Notification function called when graphic property is saved
  275. Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
  276.         ValueOld As Variant, ValueNew As Variant) As Boolean
  277.     'OK to proceed
  278.     OnPropertyChanging = True
  279. End Function
  280.  
  281. 'Notification function called when graphic property is retrieved
  282. Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
  283.     'Do nothing
  284. End Function
  285.  
  286.  
  287. 'Called when graphic's internal structure needs to be updated
  288. Public Function Regen(ByVal grfThis1 As Object)
  289.         'Setup error handler
  290.         On Error Resume Next
  291.         Err.Clear
  292. Dim grfThis As Graphic
  293.         Set grfThis = grfThis1
  294.         'Set up lock
  295.         Dim lockCount&
  296.         lockCount& = grfThis.RegenLock
  297.  
  298.         'Setup error handler (make sure lock is removed)
  299.         On Error GoTo FailedLock
  300.         If lockCount& = 0 Then
  301.             'Delete previous cosmetic children
  302.             grfThis.Graphics.Clear gfCosmetic
  303.  
  304.             Dim Info As String
  305.             Dim X As Double
  306.             Dim Y As Double
  307.  
  308.             With grfThis.Vertices
  309.                 X = .Item(0).X
  310.                 Y = .Item(0).Y
  311.             End With
  312.             Dim dx As Double
  313.             dx = grfThis.Properties("MarkSize")
  314.             Dim dy As Double
  315.             dy = dx
  316.             Dim TSize As Double
  317.             TSize = grfThis.Properties("TextHeight")
  318.  
  319.             Dim itype As Long
  320.             Dim grfText As Object
  321.  
  322.             ' Make the Cross
  323.             Dim grfLine As Object
  324.             Set grfLine = grfThis.Graphics.AddLineSingle(X - dx, Y, 0, X + dx, Y, 0)
  325.             grfLine.Cosmetic = True
  326.  
  327.             Set grfLine = grfThis.Graphics.AddLineSingle(X, Y + dy, 0, X, Y - dy, 0)
  328.             grfLine.Cosmetic = True
  329.  
  330.  
  331.             itype = grfThis.Properties("CoordType")
  332.  
  333.             ' Make the Text
  334.             Select Case itype
  335.                 Case dotted
  336.                     Info = Format(X, "0") & " "
  337.                     Set grfText = grfThis.Graphics.AddText(Info, X, Y, 0, TSize, 0#)
  338.                     grfText.Cosmetic = True
  339.  
  340.                     ' Move the X text left of the point by the width of the text
  341.                     Dim mx As Double
  342.                     With grfText.Vertices
  343.                         mx = .Item(3).X - .Item(1).X
  344.                         .Item(0).X = .Item(0).X - mx
  345.                         .Item(1).X = .Item(1).X - mx
  346.                         .Item(2).X = .Item(2).X - mx
  347.                         .Item(3).X = .Item(3).X - mx
  348.                         .Item(4).X = .Item(4).X - mx
  349.                         .Item(5).X = .Item(5).X - mx
  350.                     End With
  351.  
  352.  
  353.                     Info = " " & Format(Y, "0")
  354.                     Set grfText = grfThis.Graphics.AddText(Info, X, Y, 0, TSize, 0#)
  355.                     grfText.Cosmetic = True
  356.  
  357.  
  358.                 Case stacked
  359.                     Info = "X = " & Format(X, "0.00") & Chr(10) & "Y = " & Format(Y, "0.00")
  360.                     Set grfText = grfThis.Graphics.AddText(Info, X, Y, 0, TSize * 2, 0#)
  361.  
  362.                     grfText.Cosmetic = True
  363.  
  364.                     ' Move the X text left of the point by the width of the text
  365.                     Dim my As Double
  366.                     With grfText.Vertices
  367.                         my = (.Item(1).Y - .Item(2).Y) / 2#
  368.                         .Item(0).Y = .Item(0).Y - my
  369.                         .Item(1).Y = .Item(1).Y - my
  370.                         .Item(2).Y = .Item(2).Y - my
  371.                         .Item(3).Y = .Item(3).Y - my
  372.                         .Item(4).Y = .Item(4).Y - my
  373.                         .Item(5).Y = .Item(5).Y - my
  374.                     End With
  375.                 Case cartesian
  376.                     Info = "(" & Format(X, "0.00") & ", " & Format(Y, "0.00") & ")"
  377.                     Set grfText = grfThis.Graphics.AddText(Info, X, Y, 0, TSize, 0#)
  378.                     grfText.Cosmetic = True
  379.  
  380.             End Select
  381.  
  382.         End If
  383.  
  384.         'Remove lock
  385.         grfThis.RegenUnlock
  386.  
  387.         Exit Function
  388. FailedLock:
  389.         'Remove lock
  390.         grfThis.RegenUnlock
  391.  
  392. Failed:
  393. End Function
  394.  
  395.  
  396.  
  397.